// pages/shopping/setMeal/particulars.js
const app = getApp()
const connector = require('../../../utils/connector.js')
const WxParse = require('../../../module/wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bar_Height: wx.getSystemInfoSync().statusBarHeight + 45,
    shopping:"",
  },
  //立即购买
  optionBotBtn(e){
    let id = this.data.id
    if(app.globalData.identity){
      wx.showToast({
        title: "对不起，您不是学员，不能购买",
        icon: 'none',
        duration: 1000
      })
    }else{
      wx.navigateTo({
        url: './purchase?id=' + JSON.stringify(e.currentTarget.dataset.id),
      })
    }
    
  },
  //跳转协议
  xyGo(e){
    wx.navigateTo({
      url: '/pages/shopping/agreement/agreement',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    // console.log(JSON.parse(options.id))
    goodsDetail(that, JSON.parse(options.id))
    that.setData({
      id:JSON.parse(options.id)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新

  },
})

//获取商品详情  
function goodsDetail(that, shoppingId) {
  connector.getFunc(connector.connector().goodsDetail + shoppingId, "", "get", app.tokens, function (res) {
    if (res.statusCode == 200) {
      var arr = []
      // console.log(res.data)
      WxParse.wxParse('article', 'html', res.data.content, that);
      // console.log(res.data.content)
      app.globalData.parameter = res.data.parameter.course
      that.setData({
        shopping:res.data.content,
      })

    } else {
      wx.showToast({
        title: res.statusCode + ":" + res.errMsg,
        icon: 'none',
        duration: 1000
      })
    }
  }, function (res) {
    wx.showToast({
      title: "内部错误",
      icon: 'none',
      duration: 1000
    })
  })
}